package com.ruoyi.project.beautyflower.loanApplication.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.beautyflower.loanApplication.domain.LoanApplication;
import com.ruoyi.project.beautyflower.loanApplication.service.ILoanApplicationService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 用户借款申请 信息操作处理
 * 
 * @author lxs
 * @date 2018-10-13
 */
@Controller
@RequestMapping("/beautyflower/loanApplication")
public class LoanApplicationController extends BaseController
{
    private String prefix = "beautyflower/loanApplication";
	
	@Autowired
	private ILoanApplicationService loanApplicationService;
	
	@RequiresPermissions("beautyflower:loanApplication:view")
	@GetMapping()
	public String loanApplication()
	{
	    return prefix + "/loanApplication";
	}
	
	/**
	 * 查询用户借款申请列表
	 */
	@RequiresPermissions("beautyflower:loanApplication:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(LoanApplication loanApplication)
	{
		startPage();
        List<LoanApplication> list = loanApplicationService.selectLoanApplicationList(loanApplication);
		return getDataTable(list);
	}
	
	/**
	 * 新增用户借款申请
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存用户借款申请
	 */
	@RequiresPermissions("beautyflower:loanApplication:add")
	@Log(title = "用户借款申请", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(LoanApplication loanApplication)
	{		
		return toAjax(loanApplicationService.insertLoanApplication(loanApplication));
	}

	/**
	 * 修改用户借款申请
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		LoanApplication loanApplication = loanApplicationService.selectLoanApplicationById(id);
		mmap.put("loanApplication", loanApplication);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存用户借款申请
	 */
	@RequiresPermissions("beautyflower:loanApplication:edit")
	@Log(title = "用户借款申请", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(LoanApplication loanApplication)
	{		
		return toAjax(loanApplicationService.updateLoanApplication(loanApplication));
	}
	
	/**
	 * 删除用户借款申请
	 */
	@RequiresPermissions("beautyflower:loanApplication:remove")
	@Log(title = "用户借款申请", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(loanApplicationService.deleteLoanApplicationByIds(ids));
	}
	
}
